package com.lxr0860.lxr0860production_test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.lxr0860.lxr0860production_test.bean.ConfigItem;
import com.lxr0860.lxr0860production_test.R;

import java.util.List;

/**
 * Created by uniriho on 2018/9/3.
 */

public class ConfigAdapter extends BaseAdapter {
    private Context context;
    private List<ConfigItem> configs;

    public ConfigAdapter(Context context, List<ConfigItem> configs) {
        this.context = context;
        this.configs = configs;
    }

    @Override
    public int getCount() {
        return configs.size();
    }

    @Override
    public Object getItem(int position) {
        return configs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_configs, parent, false);
            holder.mTvConfigName = (TextView) convertView.findViewById(R.id.tv_config_item_name);
            holder.mCbConfigStatus = (CheckBox) convertView.findViewById(R.id.cb_config_item_status);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.mTvConfigName.setText((position + 1) + "." + configs.get(position).getConfigName());
        holder.mCbConfigStatus.setChecked(configs.get(position).isConfigChosed());
        return convertView;
    }

    class Holder {
        TextView mTvConfigName;
        CheckBox mCbConfigStatus;
    }
}
